package com.example.sixthweek;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class ConfigActivity extends AppCompatActivity {
    private static final String TAG = "config";
    EditText edit1;
    EditText edit2;
    EditText edit3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {//onCreate表明页面打开即执行
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);
        Log.i(TAG, "onCreate: ...");

        Intent intent = getIntent();
        float dollar = intent.getFloatExtra("dollar_key",0.0f);
        float euro = intent.getFloatExtra("euro_key",0.0f);
        float won = intent.getFloatExtra("won_key",0.0f);

        Log.i(TAG, "onCreate: dollar=" +dollar);
        Log.i(TAG, "onCreate: euro=" +euro);
        Log.i(TAG, "onCreate: won=" +won);

       edit1 = findViewById(R.id.edit1);
        String dollar1 = Float.toString(dollar);
        edit1.setText(dollar1);
         edit2 = findViewById(R.id.edit2);
        String euro1 = Float.toString(euro);
        edit2.setText(euro1);
        edit3 = findViewById(R.id.edit3);
        String won1 = Float.toString(won);
        edit3.setText(won1);
        }


    public void back(View btn){

        String newdr0 = edit1.getText().toString();
        Float newdr = Float.parseFloat(newdr0);

        String newer0 = edit2.getText().toString();
        Float newer = Float.parseFloat(newer0);

        String newwr0 = edit3.getText().toString();
        Float newwr = Float.parseFloat(newwr0);//代会数据不能使用startActivity 应该使用返回，否则会消耗内存

         //Intent intent = new Intent(this,MainActivity.class);
         //intent.putExtra("newdr_key",newdr);
         //intent.putExtra("newer_key",newer);
         //intent.putExtra("newwr_key",newwr);
         //startActivity(intent);
         Intent intent = getIntent();
         Bundle bdl = new Bundle();
         bdl.putFloat("key_dollar2",newdr);
         bdl.putFloat("key_euro2",newer);
         bdl.putFloat("key_won2",newwr);
         intent.putExtras(bdl);
         setResult(6,intent);
         finish();
    }
}